﻿using System;
using System.Data.Entity;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using WeiXinPF.Modules.CDRT.SmartCity.Domain.Models;

namespace WeiXinPF.Web
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Database.SetInitializer<SmartContext>(null);
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //可在此处建立事务，遇到异常则回滚
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError().GetBaseException();
            var exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
            bool rethrow = exManager.HandleException(ex, "WeiXinPF");
            if (rethrow)
            {
                //Response.RedirectPermanent("~/error.html");
            }
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}